package com.rykj.qxj.test.xtest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MapTestDemo {
	 public static void main(String[] args) {  
	        List<Map<String, String>> l = new ArrayList<Map<String, String>>();  
	        Map<String, String> oneMap = new HashMap<String, String>();  
	        oneMap.put("gsId", "8000");  
	        oneMap.put("gsName", "总部集中处理中心");  
	        oneMap.put("yybcount", "3");  
	        l.add(oneMap);  
	        Map<String, String> twoMap = new HashMap<String, String>();  
	        twoMap.put("gsId", "8008");  
	        twoMap.put("gsName", "南京长江路证券营业部");  
	        twoMap.put("yybcount", "14");  
	        l.add(twoMap);  
	        
	        Map<String, String> threeMap = new HashMap<String, String>();  
	        threeMap.put("gsId", "8008");  
	        threeMap.put("gsName", "南京长江路证券营业部");  
	        threeMap.put("yybcount", "5");  
	        l.add(threeMap);  
	  
	        List<Map<String, String>> countList = new ArrayList<Map<String, String>>();  
	        for (int i = 0; i < l.size(); i++) {  
	            String gsId = l.get(i).get("gsId");  
	            int flag = 0;// 0为新增数据，1为增加count  
	            for (int j = 0; j < countList.size(); j++) {  
	                String gsId_ = countList.get(j).get("gsId");  
	                if (gsId.equals(gsId_)) {  
	                    int sum = Integer.parseInt(l.get(i).get("yybcount"))  + Integer.parseInt(countList.get(j).get("yybcount"));  
	                    countList.get(j).put("yybcount", sum + "");  
	                    flag = 1;  
	                    continue;  
	                }  
	            }  
	           if (flag == 0) {  
	                countList.add(l.get(i));  
	           }  
	        }  
	        for (Map<String, String> map :countList) {  
	            System.out.println(map);  
	        }  
	    }  
	
		
}
